Page({
  data: {
    inputShowed: false,
    inputVal: "",
    list: [],
    listSearch: []
  },

  callPhone: function (e) {
    if (e.currentTarget.id == "") {
      wx.showToast({
        title: '号码为空',
        icon: 'none',
      });
      return;
    }
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.id //仅为示例，并非真实的电话号码
    });
  },

  showInput: function () {
    this.setData({
      inputShowed: true
    });
  },
  hideInput: function () {
    this.setData({
      inputVal: "",
      inputShowed: false,
      list:this.data.list
    });
  },
  clearInput: function () {
    this.setData({
      inputVal: ""
      
    });
  },

  inputTyping: function (e) {
    var that = this
    var arr = []
    var keyWord = e.detail.value

    for (var i = 0; i < that.data.listSearch.length; i++) {

      if (that.data.listSearch[i].sName.indexOf(keyWord) >= 0 || that.data.listSearch[i].sTel.indexOf(keyWord) >= 0) {
        arr.push(that.data.listSearch[i]);
      }
    }
    if (keyWord != null && keyWord != undefined && keyWord != '' && keyWord != ' ' && keyWord.length != 0) {
      that.setData({
        list: arr,
      });
    } else {
      that.setData({
        list: that.data.listSearch
      });
    }
  },


  delete:function(e){
    var that = this
    wx:wx.showModal({
      title: '确定删除?',
      content: '确定要删除这个合作司机吗？',
      showCancel: true,
      cancelText: '取消',
      confirmText: '确定',
      success: function(res) {
        if(res.confirm){
          var sijiID = e.currentTarget.dataset.idx
          var PartnerID = e.currentTarget.dataset.idpartner
          deleteParnter(that, sijiID, PartnerID)
        }else{

        }
      },
      fail: function(res) {},
      complete: function(res) {},
    })

  },

  ballClickEvent(){
    wx.navigateTo({
      url: '../../../user_center/car_company/driver_manage/AddPartnerDriver',
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
  },



  onLoad: function () {
    
  },
  onShow: function () {
    getData(this)
  },



   
})

function getData(that){
  that.data.list = []
  that.data.listSearch = []
  var userInfo = wx.getStorageSync('userInfo');

  wx.request({
    url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompPatners.ashx',
    data: {
      ID: userInfo.ZID,
      stype: 1,
      pagesize: 200,
      pageindex: 1
    },
    method: 'GET',
    success: function (res) {
      // success
      var code = res.data.code;
      if (code == 0) {
        that.setData({
          list: that.data.list.concat(res.data.data),
          listSearch: that.data.listSearch.concat(res.data.data)
        })
        console.log(that.data.list)
      }
    },
    fail: function () {
      // fail
    }
  })
}

function deleteParnter(that,sijiID, PartnerID){

  var userInfo = wx.getStorageSync('userInfo');
  wx.request({
    url: 'https://www.lanshuicar.com/Server/CarCompany/CarCompPatners.ashx',
    data: {
      stype:'3',
      sijiid:sijiID,
      ID:userInfo.ID,
      partnerid:PartnerID
    },
    method: 'GET',
    success: function (res) {
      // success
      var code = res.data.code;
      if (code == 0) {
        wx.showToast({
          title: '删除成功',
        })
        getData(that)
      }
      
    },
    fail: function () {
      // fail
    }
  })

}

